/*
 * Copyright (c) 2006-2008, Petr Panteleyev
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 * 
 *    1. Redistributions of source code must retain the above copyright notice, 
 *       this list of conditions and the following disclaimer.
 *    2. Redistributions in binary form must reproduce the above copyright notice, 
 *       this list of conditions and the following disclaimer in the documentation 
 *       and/or other materials provided with the distribution.
 *    3. The name of the author may not be used to endorse or promote products 
 *       derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.panteleyev.livejournal;

import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.table.AbstractTableModel;

import org.panteleyev.ljapi.LJFriend;
import org.panteleyev.swing.BasicDialog;
import org.panteleyev.swing.TableUtil;

/**
 *
 * @author  Petr Panteleyev
 */
@SuppressWarnings("serial")
public class BirthdayReminderDialog extends BasicDialog<JFrame> {
    private AbstractTableModel _tableModel;
    private ArrayList<LJFriend> _bList;
    
    public BirthdayReminderDialog(JFrame parent, ArrayList<LJFriend> bList) {
        super(parent);
        _bList = bList;
        
        initComponents();
        
        createTableMode();
        TableUtil.adjustTableColumnSizes(birthdayTable);
        
        java.awt.Dimension size = birthdayTable.getPreferredSize();
        if (size.getHeight() > 300) {
            size.setSize(size.getWidth(), 300);
        }        
        birthdayTable.setPreferredScrollableViewportSize(size);
        pack();
    }
    
    private void createTableMode() {
        _tableModel = new AbstractTableModel() {
            @Override
            public int getColumnCount() { 
                return 2;
            }
            
            @Override
            public int getRowCount() {
                return _bList.size();
            }

            @Override
            public Object getValueAt(int row, int col) {
                LJFriend f = _bList.get(row);
                switch (col) {
                    case 0:
                        return f.getFullName();
                    case 1:
                        return f.getBirthday();
                    default:
                        return 0;
                }
            }
            
            @Override
            public String getColumnName(int column) {
                return ""; 
            }                                    
        };
        
        birthdayTable.setModel(_tableModel);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        topPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        birthdayTable = new javax.swing.JTable();
        buttonPanel = new javax.swing.JPanel();
        okButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(L10N.BIRTHDAYS_REMINDER_DIALOG_TITLE.s());
        getContentPane().setLayout(new java.awt.GridBagLayout());

        topPanel.setPreferredSize(null);
        topPanel.setLayout(new java.awt.BorderLayout());

        jScrollPane1.setPreferredSize(null);

        birthdayTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        birthdayTable.setPreferredSize(null);
        birthdayTable.setShowHorizontalLines(false);
        birthdayTable.setShowVerticalLines(false);
        jScrollPane1.setViewportView(birthdayTable);

        topPanel.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(topPanel, gridBagConstraints);

        okButton.setText("OK");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });
        buttonPanel.add(okButton);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        getContentPane().add(buttonPanel, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        onOk();
    }//GEN-LAST:event_okButtonActionPerformed
        
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable birthdayTable;
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton okButton;
    private javax.swing.JPanel topPanel;
    // End of variables declaration//GEN-END:variables
    
}
